package co.edu.poli.ficb.agl.automatable.examples;

import java.awt.Dimension;

import javax.swing.JFrame;

import edu.uci.ics.jung.algorithms.layout.CircleLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.DirectedSparseGraph;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;

public class JungTest {
	
	public static void main(String[] args) {
		Graph<Integer, String> g = new DirectedSparseGraph<Integer, String>();
		g.addVertex(1);
		g.addVertex(2);
		g.addVertex(3);
		g.addVertex(4);
		g.addVertex(5);
		
		g.addEdge("arco12", 1, 2);
		g.addEdge("arco13", 1, 3);
		
		System.out.println(g);
		
		Layout<Integer, String> layout = new CircleLayout<Integer, String>(g);
		layout.setSize(new Dimension(300,300));
		BasicVisualizationServer<Integer, String> server = 
			new BasicVisualizationServer<Integer, String>(layout);
		server.setPreferredSize(new Dimension(350,350));
		server.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<String>());
		
		JFrame frame = new JFrame("Jung example");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add(server);
		frame.pack();
		frame.setVisible(true);
	}

}